//
//  ContractListViewController.m
//  mcosApp
//
//  Created by YaSha_Tom on 2018/12/13.
//  Copyright © 2018年 YaSha-Tom. All rights reserved.
//

#import "ContractListViewController.h"
#import "OrderListTableViewCell.h"
#import "ContractLookViewController.h"
#import "ContractInfoViewController.h"
#import "DataManager.h"
#import "ContractModel.h"
#import "UIImage+LX.h"

@interface ContractListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,copy)NSArray *dataSource;

@end

@implementation ContractListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"合同列表";
    self.view.backgroundColor =[UIColor whiteColor];
    [self initUI];
    [self doNetworking];
    [self setupNavBar];
}
- (void)setupNavBar {
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage getImageWithColor:[UIColor qmui_colorWithHexString:@"F55931"]] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
- (void)initUI {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT-kTopHeight) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 140*kHeightScale;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[OrderListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;//取消cell 的点击效果
    ContractModel *model = self.dataSource[indexPath.row];
    [cell setContractListData:model];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ContractModel *model = self.dataSource[indexPath.row];
    ContractLookViewController *contractLookViewController = [[ContractLookViewController alloc]init];
    contractLookViewController.id = model.id;
    [self.navigationController pushViewController:contractLookViewController animated:YES];
}
- (void)doNetworking{
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Domain,getContractList];
    NSDictionary *dic = @{@"pageNumber":@"1",@"pageSize":@"10",@"status":@"0"};
    [YSNetManager ys_request_GETWithUrlString:urlString isNeedCache:NO parameters:dic successBlock:^(id response) {
        NSLog(@"成功%@",response);
        if ([response[@"code"]  isEqual: @1]) {
            self.dataSource = [DataManager getContractListData:response];
            [self.tableView reloadData];
        }else{
            [QMUITips showSucceed:response[@"msg"] inView:self.view hideAfterDelay:1];
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"失败%@",error);
    } progress:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
